﻿//using ServiceStack.Redis;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;

namespace RedisClients
{
    public class RedisRepository
    {
        public static string tcpString = "127.0.0.1:6379";
        public ConnectionMultiplexer conn;
        public IDatabase dbContext;

        public RedisRepository(string _tcpString) 
        {
            tcpString = _tcpString;
            conn = ConnectionMultiplexer.Connect(tcpString);
            dbContext = conn.GetDatabase();
        }
        public RedisRepository() 
        {
            conn = ConnectionMultiplexer.Connect(tcpString);
            dbContext = conn.GetDatabase();
        }

        public static RedisRepository CreateClient(string tcp) 
        {
            try
            {
                return new RedisRepository(tcp);
            }
            catch (Exception e)
            {
                throw new TypeInitializationException("求你输个正确的IP", e);
            }
        }

        public long AddToListTop<TEntity>(string listKey, TEntity entity) 
        {
           return dbContext.ListLeftPush(listKey, Newtonsoft.Json.JsonConvert.SerializeObject(entity));
        }


      
    }
}
